package cn.wolfcode.wolfcodemall.controller.admin;

import cn.wolfcode.wolfcodemall.domain.Admin;
import cn.wolfcode.wolfcodemall.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.Map;


@Controller
@RequestMapping("/admin")
public class AccountController {
    @Autowired
    private AdminService adminService;

    /**
     * 我的账户
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/account")
    public String account(Model model,HttpSession session){
        Admin admin= (Admin) session.getAttribute("admin");
        model.addAttribute("admin",admin);
        return "/admin/accountManagePage";
    }

    /**
     * 修改用户密码
     * @param admin_id
     * @param map
     * @return
     */
    @RequestMapping("/account/{admin_id}")
    public String upd(@PathVariable("admin_id") Integer admin_id,
                       @RequestParam Map<String, Object> map){
        map.put("adminId", admin_id);
        adminService.updateAdmin(map);
        System.out.println(map);
        return "/admin/accountManagePage";
    }

    /**
     * 注销用户
     * @return
     */
    @RequestMapping("/logout")
    public String logout(){
        return "/admin/loginPage";
    }


}
